package com.http;

import org.json.JSONObject;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;
import com.modle.UserOrgInfo;
import com.util.JsonUtil;

/**
 * 
 * @ClassName:UserOrgInfoTask
 * @Description:TODO获取机构信息
 * @author zhuw
 * @date 2013-8-22 下午11:25:56
 */
public class UserOrgInfoTask extends AsyncTask<String, Void, ResultUserOrgInfo> {
	public static interface CallBack extends NetWorkCallBack {
		
		public abstract void procUserOrgInfo(UserOrgInfo data);

	}

	CallBack callback;

	public UserOrgInfoTask(CallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultUserOrgInfo doInBackground(String... params) {
		ResultUserOrgInfo data = null;
		try {
			ResEntity re=NetConUtil.sendGetRequestEntity(ServerPath.ORG_INFO_PATH+params[0]);
			if(re.code==ResEntity.S_OK){
				UserOrgInfo user=JsonUtil.parseUserOrgInfo(new JSONObject(re.jsonStr));
			    data= new ResultUserOrgInfo(CommonData.H_FLAG_SUCCESS, null, user);
			}else if(re.code==ResEntity.S_FAILED){
				
				  data= new ResultUserOrgInfo(CommonData.H_FLAG_ERROR, "code:"+re.code+"    "+re.jsonStr, null);
				
			}else{
				  data= new ResultUserOrgInfo(CommonData.H_FLAG_ERROR, "code:"+re.code+ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data= new ResultUserOrgInfo(CommonData.H_FLAG_ERROR, ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultUserOrgInfo result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.procUserOrgInfo(result.data);

		} else {
			callback.procError(result.msg);
		}

	}
}
